package dao;

import java.sql.Timestamp;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import util.TimeStamp;

import entity.TIpApply;
import bean.IpApplyForm;

public class TIpApplyDao extends HibernateDao {

    public static void saveIpApply(IpApplyForm objFrm, String userId) {

        String place = objFrm.getPlace();
        String macAddress = objFrm.getMacAddress();
        String message = objFrm.getMessage();

        TIpApply tIpApply = new TIpApply();
        tIpApply.setPlace(place);
        tIpApply.setStatus(new Integer(0));
        tIpApply.setMacAddress(macAddress);
        tIpApply.setMessage(message);
        tIpApply.setUserId(userId);
        tIpApply.setApplyTime(TimeStamp.getCurrentTs());
        tIpApply.setLastUpdateTime(TimeStamp.getCurrentTs());

        Session session = getSession();
        Transaction trans = session.beginTransaction();
        session.save(tIpApply);
        trans.commit();
        session.close();

    }

    @SuppressWarnings("unchecked")
    public static List<TIpApply> getAllApply() {
        Session session = getSession();

        List<TIpApply> list = (List<TIpApply>) session.createCriteria(
                TIpApply.class).list();
        session.close();

        return list;

    }
    
    public static TIpApply getIpApplyDetail(Integer applyId) {
        Session session = getSession();
        
        TIpApply ret = (TIpApply) session.get(TIpApply.class, applyId);
        
        return ret;
    }
}
